﻿//-----------------------------------------------------------------------
// <copyright file="UserAccountFactory.cs" company="Mulala">
//     Copyright Mulala. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Mulala.Cavan.Domain.MainBoundedContext.SecurityModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.ChargeModule;
    using Mulala.Cavan.Domain.MainBoundedContext.LogModule;
    using Mulala.Cavan.Domain.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.Setting;
    using Mulala.Cavan.Core.Cryptography;

    public static class UserAccountFactory
    {
        public static UserAccount CreateUserAccount(
                                        string name,
                                        string password,
                                        string email,
                                        int score,
                                        int experience,
                                        int liveness,
                                        int askCount,
                                        int answerCount,
                                        int acceptedCount,
                                        DateTime lastActiveTime,
                                        bool isLocked,
                                        bool isDeleted,
                                        decimal creditLimit,
                                        IList<Role> roles,
                                        IList<UserService> userServices,
                                        IList<VisitHistory> visitors,
                                        IList<Note> notes,
                                        IList<UserMessage> userMessages,
                                        DateTime editTime,
                                        string editUser)
        {
            UserAccount userAccount = new UserAccount();
            userAccount.AcceptedCount = acceptedCount;
            userAccount.AnswerCount = answerCount;
            userAccount.AskCount = askCount;
            userAccount.EditTime = editTime;
            userAccount.EditUser = editUser;
            userAccount.Email = email;
            userAccount.Experience = experience;
            userAccount.IsDeleted = isDeleted;
            userAccount.IsLocked = isLocked;
            userAccount.LastActiveTime = lastActiveTime;
            userAccount.Liveness = liveness;
            userAccount.Name = name;
            userAccount.Notes = notes;
            userAccount.Password = password;
            userAccount.CreditLimit = creditLimit;
            userAccount.Roles = roles;
            userAccount.Score = score;
            userAccount.UserMessages = userMessages;
            userAccount.UserServices = userServices;
            userAccount.Visitors = visitors;
            userAccount.CreateTime = DateTime.Now;

            return userAccount;
        }

        public static UserAccount CreateUserAccount(
                                        string name,
                                        string password,
                                        string email,
                                        IList<Role> roles)
        {
            password = Crypto.Encrypt(password);
            UserAccount userAccount = UserAccountFactory.CreateUserAccount(name, password, email, Project.Settings.DefaultScore, Project.Settings.DefaultProprietorExperience,
                                                                                       Project.Settings.DefaultLiveness, Project.Settings.DefaultAskCount, Project.Settings.DefaultAnswerCount,
                                                                                       Project.Settings.DefaultAcceptedCount, DateTime.Now, false, false, 0, roles, null,
                                                                                       null, null, null, DateTime.Now, name);
            return userAccount;
        }

        public static UserAccount CreateUserAccount(
                                       string name)
        {
            UserAccount userAccount = new UserAccount();
            userAccount.Name = name;

            return userAccount;
        }

        public static UserAccount CreateUserAccount(
                               int id)
        {
            UserAccount userAccount = new UserAccount();
            userAccount.ID = id;

            return userAccount;
        }

        public static UserAccount CreateUserAccount(
                               int id,
                                SecurityIdentifier.Role role)
        {
            UserAccount userAccount = new UserAccount();
            userAccount.ID = id;
            userAccount.Roles = new List<Role>();
            userAccount.Roles.Add(RoleFactory.CreateRole(role.GetHashCode()));

            return userAccount;
        }
    }
}
